package com.cjjd.c.feature.mine.order;

import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.BaseSwipeRefreshFragment;
import com.cjjd.c.base.MyBaseAdapter;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.bean.ListResult;
import com.cjjd.c.bean.RoomOrderItembean;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.SharePrefUtil;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Response;

/**
 * ----------------------------------
 * Created by xyd on 2017/8/15.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class MyOrderFragment extends BaseSwipeRefreshFragment implements View.OnTouchListener {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }


    @Override
    public Object getTitleString() {
        return "我的订单";
    }

    @Override
    protected void initView() {
        super.initView();
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setMargins(0, (int) (10 * getResources().getDisplayMetrics().density + 0.5), 0, 0);
        listBase.setLayoutParams(layoutParams);
        listBase.setDivider(getResources().getDrawable(R.drawable.order_divider));
        listBase.setDividerHeight((int) (10 * mContext.getResources().getDisplayMetrics().density + 0.5));
    }

    @Override
    public void responseSuccess(Call<HttpResult> call, Response<HttpResult> response) {
        ListResult<RoomOrderItembean> listResult = (ListResult<RoomOrderItembean>) response.body().getData();
        setDataList(listResult.dataList);
    }

    @Override
    public MyBaseAdapter getAdapter() {
        return new OrderAdapter(mContext,OrderAdapter.ORDER);
    }

    @Override
    public Call<HttpResult> getCall() {
        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));

        return service.getRoomOrderList(JsonUtils.convertParam("getRoomOrderList", h1));

    }
}
